package com.example.chapter6demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.chapter6demo.dao.StudentMapper;
import com.example.chapter6demo.entity.Student;
import com.example.chapter6demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Autowired
    StudentMapper studentMapper;

    @Override
    public Page getPage(String stuName, Integer pageNum) {
        Page page = new Page(pageNum, 3);
        LambdaQueryWrapper<Student> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.hasText(stuName)) {
            queryWrapper.like(Student::getStudentname,stuName);
        }
//        //倒序
//        queryWrapper.orderByDesc(Student::getId);
        return this.page(page, queryWrapper);
    }
}
